<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet" href="../css/main.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	findByAll();
});

function findByAll() {
	$.get("../admin/findAll", null, function(data){
		var str = "";
		$.each(data, function(index, item) {
			str += "<tr><td>"+item.aid+"</td><td>"+item.aname+"</td><td>"+item.tel+"</td><td><a href='javascript:resetPwd("+item.aid+")'>[重置密码]</a></td></tr>";
		});
		$("#admin_info").html("").append($(str));
	},"json");
}

//function createTable(data,  )

function addNewsTypeInfo(){
	var aname=$.trim( $("#tname").val() );
	var pwd=$.trim( $("#pwd").val() );
	var tel=$.trim( $("#tel").val() );
	
	if (aname == "") {
		alert("请输入管理员姓名...");
		return;
	}
	
	if (pwd == "") {
		alert("请输入管理员密码...");
		return;
	}
	
	if (tel == "") {
		alert("请输入管理员手机号码...");
		return;
	}
	
	$.post("../admin/add", {aname:aname, pwd:pwd, tel:tel}, function(data){
		data = parseInt($.trim(data));
		if (data > 0) {
			$("#myform")[0].reset();
			findByAll();
		} else {
			alert("管理员信息添加失败，请稍后重试...");
		}
	},"text");
}

function resetPwd(aid) {
	$.post("../admin/update", {aid:aid}, function(data){
		data = parseInt($.trim(data));
		if (data > 0) {
			alert("管理员密码已重置为手机号码后 6 位，请提醒用户及时修改..");
		} else {
			alert("管理员密码重置失败...");
		}
	},"text");
}
</script>
</head>
<body>
<div id="forms" class="mt10">
	<div class="box">
		<div class="box_border">
			<div class="box_center">
				<form id="myform">
				姓名：<input type="text" id="tname" class="input-text lh30" size="40"/>&nbsp;&nbsp;
				密码：<input type="password" id="pwd" class="input-text lh30" size="40"/>&nbsp;&nbsp;
				手机号码：<input type="tel" id="tel"class="input-text lh30" size="40"/>&nbsp;&nbsp;
				<input type="button" name="button" class="btn btn82 btn_save2" onclick="addNewsTypeInfo()" value="添加"/>&nbsp;&nbsp;
				</form>
			</div>
		</div>
	</div>
</div>

<div id="table" class="mt10">
	<div class="box span10 oh">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table">
			<thead>
				<tr>
					<th width="20%">编号</th>
                   	<th width="30%">姓名</th>
                   	<th width="30%">联系方式</th>
                   	<th>操作</th>
                </tr>
             </thead>
             <tbody id="admin_info" align="center">
				
             </tbody>
		</table>
	</div>
</div>
</body>
</html>